﻿<?xml version="1.0" encoding="utf-8"?>
<!--
        作者：          liuleyi
        更新时间：      20170227
        用途：          生成存储过程默认模板
-->
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="text" indent="no" encoding="utf-8" byte-order-mark="no"/>  
	<xsl:template match="/">
	<xsl:result-document encoding="utf-8" method="text" href="./generate/python/views.py">
	<xsl:variable name="StringTypeDefine" select="document('../model/0101_StringTypeDefine.xml')"/>
	<xsl:variable name="EnumTypeDefine" select="document('../model/0102_EnumTypeDefine.xml')"/>
	<xsl:variable name="BooleanTypeDefine" select="document('../model/0103_BooleanTypeDefine.xml')"/>
	<xsl:variable name="DateTypeDefine" select="document('../model/0104_DateTypeDefine.xml')"/>
	<xsl:variable name="NumberTypeDefine" select="document('../model/0105_NumberTypeDefine.xml')"/>
	<xsl:variable name="FunNoConfig" select="document('../model/0601_FunNoConfig.xml')"/>
	<xsl:variable name="IntegerTypeDefine" select="document('../model/0106_IntegerTypeDefine.xml')"/>#-*- encoding:UTF-8 -*-
from django.shortcuts import get_object_or_404, render
from django.template import loader
from django.http import HttpResponse
from django.http import Http404
from . import db
from . import constant
def index(request):
    return render(request, 'index.html')
def top(request):
    return render(request, 'top.html')
def menu(request):
    return render(request, 'menu.html')
def main(request):
    return render(request, 'main.html')
def login(request):
#   if request.method == 'POST':
#       if request.session.test_cookie_worked():
#           request.session.delete_test_cookie()
#           return HttpResponse("You're logged in.")
#       else:
#           return HttpResponse("Please enable cookies and try again.")
#   request.session.set_test_cookie()
    return render(request, 'login.html')
<xsl:for-each select="FunNoConfig/FunNo">
#<xsl:value-of select="@label"/>
def <xsl:value-of select="@code"/>(request<xsl:for-each select="Request"><xsl:for-each select="Column">,<xsl:value-of select="@name"/></xsl:for-each><xsl:for-each select="Field">,<xsl:value-of select="@name"/></xsl:for-each></xsl:for-each>):
    resp = db.<xsl:value-of select="@code"/>('Pi_Operid',<xsl:for-each select="Request"><xsl:for-each select="Column"><xsl:value-of select="@name"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:for-each>)
<xsl:for-each select="Response//Column[@transmission='true']">    V_<xsl:value-of select="@name"/>=None
</xsl:for-each>
 
<xsl:for-each select="Response//Column[@transmission='true']">    V_<xsl:value-of select="@name"/>=resp.listdata[0][constant.GV_<xsl:value-of select="@name"/>]
</xsl:for-each>

    context = {'resp': resp<xsl:for-each select="Request//Column[@transmission='true']">,'<xsl:value-of select="@name"/>':<xsl:value-of select="@name"/></xsl:for-each><xsl:for-each select="Request//Field">,'<xsl:value-of select="@name"/>':<xsl:value-of select="@name"/></xsl:for-each><xsl:for-each select="Response//Column[@transmission='true']">,'<xsl:value-of select="@name"/>':V_<xsl:value-of select="@name"/></xsl:for-each>}
<xsl:choose><xsl:when test="@FunNo!=''">
<xsl:variable name="FunNo" select="@FunNo"/>
    if resp.ErrorCode!=0:
        return render(request, '<xsl:value-of select="lower-case(@template)"/>.html', context)
    else:
        return <xsl:value-of select="$FunNo"/>(request<xsl:for-each select="$FunNoConfig//FunNo[@code=$FunNo]"><xsl:for-each select="Request"><xsl:for-each select="Column">,<xsl:value-of select="@name"/></xsl:for-each></xsl:for-each></xsl:for-each>)</xsl:when><xsl:otherwise>    
<xsl:choose><xsl:when test="@error!=''">
    if resp.ErrorCode!=0:
        return render(request, '<xsl:value-of select="lower-case(@error)"/>.html', context)
    else:
        return render(request, '<xsl:value-of select="lower-case(@template)"/>.html', context)
</xsl:when><xsl:otherwise>
    return render(request, '<xsl:value-of select="lower-case(@template)"/>.html', context)
</xsl:otherwise></xsl:choose>
		</xsl:otherwise></xsl:choose>
</xsl:for-each>
<xsl:for-each select="FunNoConfig/GoNo">
#<xsl:value-of select="@label"/>
def <xsl:value-of select="@code"/>(request):
    return render(request, '<xsl:value-of select="lower-case(@template)"/>.html')
</xsl:for-each>
</xsl:result-document></xsl:template>  
</xsl:stylesheet>